package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 注解插入时，用这个
     * 获取主键值，并且赋值给id属性，不然flavor.setDishId(dish.getId());无法获取到id值
     *
     * @param dish
     * @Options(useGeneratedKeys = true, keyProperty = "id")
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    Page<DishVO> getDishPage(DishPageQueryDTO dishDTO);

    void deleteDish(List<Long> ids);

    List<Dish> selectDishById(List<Long> ids);

    Dish getDishById(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    List<Dish> list(Dish dish);

    List<Dish> getDishByCategoryId(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
